Skip to content

Handle multiple simultaneous block editor layouts#16184

Merged
bergmania merged 2 commits intov14/devfrom
v14/fix/block-editors-multiple-layouts
Apr 30, 2024
Merged

Handle multiple simultaneous block editor layouts#16184
bergmania merged 2 commits intov14/devfrom
v14/fix/block-editors-multiple-layouts

Conversation

@kjac
Copy link
Copy Markdown
Contributor

@kjac kjac commented Apr 29, 2024

Prerequisites

  • I have added steps to test this contribution in the description below

Description

The original RFC for block editors states that a Block Editor should theoretically be able to store multiple simultaneous block layouts.

However, while removing the explicit JSON technology dependencies in the Block Editor implementation in favour of a strongly typed approach, we (yours truly) accidentally managed to enforce one type of block layout for all layouts in any given Block Editor. And that's obviously incorrect.

Unfortunately we cannot know about the concrete block layout implementations of other Block Editors when (de)serializing a concrete Block Editor instance. This means we can only (de)serialize layouts that belong to the concrete Block Editor instance in question.

To that end, this PR introduces a custom JSON converter - the JsonBlockValueConverter. This converter explicitly handles the (de)serialization of the block layouts while farming off the rest of the BlockValue (de)serialization to the default JSON serializer.

Potential data loss

The JsonBlockValueConverter will actively discard any "unknown" block layouts while (de)serializing a concrete Block Editor instance. This can very well result in data loss, i.e. if a subsequent save is performed on top of a serialized value.

In effect, though, we have yet to actually see multiple simultaneous block layouts within a Block Editor instance. As a matter of fact, V13 will positively not work with multiple layouts within a Block Grid instance, and possibly it will also break for a Block List. So - in terms of potential data loss, we are likely in the clear here 😉

Testability

While working through various scenarios for this PR, I quickly realised that the RTE would not allow for unit/integration testing these things, because it relied on some obsolete constructors and subsequent static instance resolving. In other words - I had to fix that in this PR too, in order to test all these changes properly.

Testing this PR

It should be possible to edit Block Editors as per usual:

  • Block List
  • Block Grid
  • Blocks in the RTE

See also the added and updated unit/integration tests for interesting scenarios 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants